package com.sanyou.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.sanyou.pojo.vo.MaintainDataVo;
import com.sanyou.service.ClientService;
import com.sanyou.service.ProductService;
import com.sanyou.service.UserService;
import com.sanyou.utils.PagedResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class ClientServiceImpl implements ClientService {
    @Autowired
    private ProductService productService;

    @Autowired
    private UserService userService;

    @Override
    public PagedResult selectProductMaintainDataByUserId(String userId, Integer page, Integer pageSize) {
        /**
         * 根据用户Id获取其所属车间的车间Id
         */
        String subFactoryId = userService.getUserById(userId).getSubFactoryId();

        /**
         * 根据车间Id分页查询该车间下所有正处于维修状态的阴极板的维修信息
         */
        //开始分页
        PageHelper.startPage(page,pageSize);
        //查询正在维修的阴极板信息
        List<MaintainDataVo> maintainDataList = productService.selectProductMaintainDataBySubFactoryId(null,null, subFactoryId);
        //数据封装
        PageInfo<MaintainDataVo> pageList = new PageInfo<>(maintainDataList);
        PagedResult pagedResult = new PagedResult();
        pagedResult.setPage(pageList.getPageNum()); //设置当前页号
        pagedResult.setTotal(pageList.getPages()); //设置总页数
        pagedResult.setRows(pageList.getList()); //设置内容
        pagedResult.setRecords(pageList.getTotal()); //设置总记录数

        /**
         * 返回分页查询结果
         */
        return pagedResult;
    }
}
